package Functions;


/**
 * Write a description of class Messages here.
 * 
 * @author The_MMHoritz3
 * @version 1.1
 * @date 19.10.2014
 */

import net.canarymod.api.entity.living.humanoid.Player;
import net.canarymod.chat.MessageReceiver;

public class Messages
{   
    public static void sendPlayerWelcomeMessage(Player player)
    {
        if(player.getFirstJoined()!="")
        {
            player.message(getEndWelcomeMessage(player.getName()));
        }else
        {
            player.message(getEndWelcomeMessageFirstJoin(player.getName()));
        }
    }
    
    public static void sendPlayerWelcomeMessage(MessageReceiver player)
    {
        getEndWelcomeMessage(player.getName());
    }
    
    public static void openRulesForUser(MessageReceiver caller)
    {
        caller.message(net.canarymod.chat.Colors.LIGHT_RED + "!!!!Rules!!!!" + net.canarymod.chat.Colors.WHITE);
        caller.message("Everybody is Welc0me on th1s server");
        caller.message("The 4dministration is no traveling company");
        caller.message("");
    }
    
    private static String getEndWelcomeMessageFirstJoin(String PlayerName)
    {
        String welcomeMessage = "";
        String readedWelcomeMessage=""/* = Xml.XmlWriter.getWelcomeMessage()*/;
        for(int i  = 0;i<readedWelcomeMessage.length();i++)
        {
            if(readedWelcomeMessage.charAt(i)=='!')
            {
                if(readedWelcomeMessage.charAt(i+1)=='p')
                {
                    welcomeMessage += PlayerName;
                    i++;
                }else if(readedWelcomeMessage.charAt(i+1)=='p')
                {
                    welcomeMessage += getCountOfPlayerMessages();
                    i++;
                }
            }else
            {
                welcomeMessage+=readedWelcomeMessage.charAt(i);
            }
        }
        return welcomeMessage;
    }    
    
    private static String getEndWelcomeMessage(String PlayerName)
    {
        String welcomeMessage = "";
        String readedWelcomeMessage=""/* = Xml.XmlWriter.getWelcomeMessage()*/;
        for(int i  = 0;i<readedWelcomeMessage.length();i++)
        {
            if(readedWelcomeMessage.charAt(i)=='!')
            {
                if(readedWelcomeMessage.charAt(i+1)=='p')
                {
                    welcomeMessage += PlayerName;
                    i++;
                }else if(readedWelcomeMessage.charAt(i+1)=='p')
                {
                    welcomeMessage += getCountOfPlayerMessages();
                    i++;
                }
            }else
            {
                welcomeMessage+=readedWelcomeMessage.charAt(i);
            }
        }
        return welcomeMessage;
    }
    
    private static int getCountOfPlayerMessages()
    {
        return 0;
    }
}
